package deltax.common.log
{
    import __AS3__.vec.*;
    import flash.events.*;
    import flash.system.*;

    public class LogManager extends EventDispatcher
    {
        private var m_logContent:String = "";
        private var m_recordLogLevel:uint;
        private var m_enable:Boolean;
        public static const LOG_ADDED:String = "LogAdded";
        public static const LOG_CLEANED:String = "LogCleaned";
        private static var m_instance:LogManager;
        private static const LOG_LEVEL_NAMES:Vector.<String> = new Vector.<String>(LogLevel.COUNT, true);

        public function LogManager(param1:SingletonEnforcer)
        {
            LOG_LEVEL_NAMES[LogLevel.DEBUG_ONLY] = "(DebugOnly)";
            LOG_LEVEL_NAMES[LogLevel.FATAL] = "(FatalError)";
            LOG_LEVEL_NAMES[LogLevel.INFORMATIVE] = "(Informative)";
            LOG_LEVEL_NAMES[LogLevel.IMPORTANT] = "(Important)";
            this.m_enable = Capabilities.isDebugger;
            return;
        }// end function

        public function get recordLogLevel() : uint
        {
            return this.m_recordLogLevel;
        }// end function

        public function set recordLogLevel(param1:uint) : void
        {
            this.m_recordLogLevel = Math.min((LogLevel.COUNT - 1), param1);
            return;
        }// end function

        public function get enable() : Boolean
        {
            return this.m_enable;
        }// end function

        public function set enable(param1:Boolean) : void
        {
            this.m_enable = param1;
            return;
        }// end function

        public function log(param1:uint, ... args) : void
        {
            if (!this.m_enable)
            {
                return;
            }
            trace.apply(null, args);
            if (param1 < this.m_recordLogLevel)
            {
                return;
            }
            args = new Date();
            var _loc_4:* = int(args.hours).toString();
            _loc_4 = int(args.hours).toString() + ":";
            _loc_4 = _loc_4 + int(args.minutes).toString();
            _loc_4 = _loc_4 + ":";
            _loc_4 = _loc_4 + int(args.seconds).toString();
            _loc_4 = _loc_4 + LOG_LEVEL_NAMES[param1];
            var _loc_5:* = args.length;
            var _loc_6:uint = 0;
            while (_loc_6 < _loc_5)
            {
                
                if (!args[_loc_6])
                {
                }
                else
                {
                    _loc_4 = _loc_4 + args[_loc_6].toString();
                    _loc_4 = _loc_4 + " ";
                }
                _loc_6 = _loc_6 + 1;
            }
            _loc_4 = _loc_4 + "\n";
            if (param1 >= LogLevel.FATAL)
            {
                _loc_4 = _loc_4 + "\n";
                _loc_4 = _loc_4 + new Error().getStackTrace();
            }
            this.m_logContent = this.m_logContent + _loc_4;
            if (hasEventListener(LOG_ADDED))
            {
                dispatchEvent(new DataEvent(LOG_ADDED, false, false, _loc_4));
            }
            return;
        }// end function

        public function clearLog() : void
        {
            this.m_logContent = "";
            if (hasEventListener(LOG_CLEANED))
            {
                dispatchEvent(new Event(LOG_CLEANED));
            }
            return;
        }// end function

        public function get allLog() : String
        {
            return this.m_logContent;
        }// end function

        public static function get instance() : LogManager
        {
            var _loc_1:* = m_instance || new LogManager(new SingletonEnforcer());
            m_instance = m_instance || new LogManager(new SingletonEnforcer());
            return _loc_1;
        }// end function

    }
}

class SingletonEnforcer extends Object
{

    function SingletonEnforcer()
    {
        return;
    }// end function

}

